﻿using System.Web.Mvc;
using RESTController.Lib;

namespace RESTController
{
    public static class TempDataDictionaryExtensions
    {
        internal static void ClearFlashFromTempData(this TempDataDictionary tempDataDictionary)
        {
            tempDataDictionary[RESTControllerContants.FLASH_TYPE] = FlashType.None;
            tempDataDictionary[RESTControllerContants.FLASH_MESSAGE] = null;
        }

        public static void Error(this TempDataDictionary tempDataDictionary, string errorMessage)
        {
            tempDataDictionary.WriteToTempData(FlashType.Error, errorMessage);
        }

        public static void Info(this TempDataDictionary tempDataDictionary, string infoMessage)
        {
            tempDataDictionary.WriteToTempData(FlashType.Info, infoMessage);
        }

        public static void Success(this TempDataDictionary tempDataDictionary, string successMessage)
        {
            tempDataDictionary.WriteToTempData(FlashType.Success, successMessage);
        }

        public static void Warning(this TempDataDictionary tempDataDictionary, string warningMessage)
        {
            tempDataDictionary.WriteToTempData(FlashType.Warning, warningMessage);
        }

        private static void WriteToTempData(this TempDataDictionary tempDataDictionary, FlashType flashType, string flashMessage)
        {
            tempDataDictionary[RESTControllerContants.FLASH_TYPE] = flashType;
            tempDataDictionary[RESTControllerContants.FLASH_MESSAGE] = flashMessage;
        }
    }
}
